package com.simplerobot.service;



import com.simplerobot.consume.Page;
import com.simplerobot.core.BaseService;
import com.simplerobot.dao.SpiderDao;
import com.simplerobot.entity.TieBaEntity;
import com.simplerobot.robot.tieba.TieBa;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/3/8.
 */
public class SpiderService extends BaseService implements SpiderServiceInf {

    @Override
    public void insertBatch(String threadName, List<Page> pages) {
        List<TieBaEntity> tieBaEntitys = new ArrayList<>();
        TieBaEntity tieBaEntity;
        TieBa tieBa;
        for(Page page:pages){
            tieBaEntity = new TieBaEntity();
            tieBa=(TieBa)page.getModel();
            tieBaEntity.setTitle(tieBa.getTitle());
            tieBaEntity.setAuthor(tieBa.getAuthor());
            tieBaEntity.setContext(tieBa.getContext());
            tieBaEntity.setThreadName(threadName);
            tieBaEntitys.add(tieBaEntity);

        }
        SpiderDao spiderDao  = (SpiderDao)getDao(SpiderDao.class);
        spiderDao.insertBatch(tieBaEntitys);
    }
}
